package com.ra.landlord;

import java.math.BigDecimal;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;

import com.ra.landlord.constant.FeeRuleCalcMode;
import com.ra.landlord.constant.FeeRuleType;
import com.ra.system.Version;

/**
 * 收费规则定义
 * 
 * 管理费，
 * type = 1, calcMode = 0, unit = 元
 * 水表费
 * type = 2, calcMode = 0, unit = 元/吨
 * 电费
 * type = 2, calcMode = 1, unit = 元/度
 * 
 * 
 * @author Jerry.Feng Date: 2014-07-31
 */
@Entity
@Table(name = "ra_feerulecfgdesc")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class FeeRuleCfgDesc implements Version, LandlordOwner {
	
	private Integer id;
	
	// 水费，电费， 管理费等
	private String name;
	
	// 分类（0 - 无意义，  1 - 固定费用， 2 - 仪表费用）
	private FeeRuleType type;

	private String description;
	
	// 表的初始值 
	private BigDecimal initialValue;
	
	// 损耗值 
	private BigDecimal lossValue;
	
	// 备率 （比方1倍， 1.5倍）
	private BigDecimal magnification;
	
	// 计算方式 
	// 0 - 正常， 1 - 门限
	private FeeRuleCalcMode calcMode;
	
	private List<FeeRuleCfg> feeRuleCfgs;
	
	// 单位： 元
	private String unit;
	
	private LandlordOwnerUser landlordUser;
	
	// 是否为分摊费用
	private Boolean isShare;

	private Integer version;
	
	private Integer status;
	
	@Id
	@GeneratedValue
	@Column(name = "FeeItemDescId")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name = "FeeItemDescName")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "FeeItemDesctype")
	public FeeRuleType getType() {
		return type;
	}

	public void setType(FeeRuleType type) {
		this.type = type;
	}

	@Column(name = "Description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "initial_value")
	public BigDecimal getInitialValue() {
		return initialValue;
	}

	public void setInitialValue(BigDecimal initialValue) {
		this.initialValue = initialValue;
	}

	@Column(name = "Loss_value")
	public BigDecimal getLossValue() {
		return lossValue;
	}

	public void setLossValue(BigDecimal lossValue) {
		this.lossValue = lossValue;
	}

	@Column(name = "Magnification")
	public BigDecimal getMagnification() {
		return magnification;
	}

	public void setMagnification(BigDecimal magnification) {
		this.magnification = magnification;
	}

	@Column(name = "Calcmode")
	public FeeRuleCalcMode getCalcMode() {
		return calcMode;
	}

	public void setCalcMode(FeeRuleCalcMode calcmode) {
		this.calcMode = calcmode;
	}

	@Column(name = "unit")
	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}
	
	@OneToMany(cascade=CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "feeRuleCfgDesc")
	@Where(clause = "data_status = 1")
	public List<FeeRuleCfg> getFeeRuleCfgs() {
		return feeRuleCfgs;
	}

	public void setFeeRuleCfgs(List<FeeRuleCfg> feeRuleCfgs) {
		this.feeRuleCfgs = feeRuleCfgs;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "createuserid")
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}

	@Column(name = "version_id")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Column(name = "data_status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public Boolean getIsShare() {
		return isShare;
	}

	public void setIsShare(Boolean isShare) {
		this.isShare = isShare;
	}
}
